home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 14484 < prev    next >
Encoding:
Text File  |  1996-08-05  |  884 b   |  33 lines

  1. Path: csugrad.cs.vt.edu!not-for-mail
  2. From: rsuri@csugrad.cs.vt.edu (Raj Suri)
  3. Newsgroups: comp.lang.c++
  4. Subject: 2 D arrays in C++ constructors
  5. Date: 31 Mar 1996 02:37:06 -0500
  6. Organization: Virginia Tech Computer Science Dept, Blacksburg, VA
  7. Message-ID: <4jlcn2$kvl@csugrad.cs.vt.edu>
  8. X-Newsreader: TIN [version 1.2 PL2]
  9.  
  10. Ok,
  11. I wrote a c++ class that used an array of integers.  However, I didn't know the
  12. size of the array until the constructor was called.  So I did this:
  13.  
  14. class ... {
  15.  
  16.  private:
  17.   int* ptr;
  18.  
  19. And then in the constructor, I had this code:
  20.  
  21.   ptr = new int[10];
  22.  
  23. This works fine.  However, now I need to use a two dimensional array in 
  24. which I don't know the dimensions until the constructor is called.  I can't
  25. figure out how to declare ptr and allocate space to it such that I could do the
  26. following statement:
  27.  
  28. ptr[2][3] = 4;
  29.  
  30. Any help.. Thanks in advance.
  31. -Raj
  32.  
  33.